package indi.jp.project.process.controller;

import indi.jp.project.core.entity.JsonResult;
import indi.jp.project.process.entity.FlowTypeNode;
import indi.jp.project.process.service.FlowService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * 流程Controller
 *
 * @author jiangping
 * @date 2022/5/3
 */
@RestController
@RequestMapping("/flow")
public class FlowController {

    @Resource
    private FlowService flowService;

    @GetMapping("/queryTypes")
    public JsonResult queryTypes() throws Exception {
        return flowService.queryTypeList();
    }

    @GetMapping("/queryTypeNodes")
    public JsonResult queryTypeNodes(HttpServletRequest request) throws Exception {
        String typeId = request.getParameter("typeId");
        return flowService.queryTypeNodes(typeId);
    }

    @GetMapping("/queryFlowByTypeCode")
    public JsonResult queryFlowByTypeCode(HttpServletRequest request) throws Exception{
        String typeCode = request.getParameter("typeCode");
        return flowService.queryFlowByTypeCode(typeCode);
    }

    @PostMapping("/save")
    public JsonResult save(@RequestBody @Valid FlowTypeNode flowTypeNode) throws Exception {
        return flowService.save(flowTypeNode);
    }

    @PostMapping("/deleteById")
    public JsonResult deleteById(@RequestParam String id) throws Exception {
        return flowService.deleteById(id);
    }

    @PostMapping("/initTypeNodes")
    public JsonResult initTypeNodes(@RequestBody FlowTypeNode flowTypeNode) throws Exception {
        return flowService.initTypeNodes(flowTypeNode);
    }
}
